package com.wen.es.utils;

import com.wen.es.annotation.EsTypeAnno;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by LAIO on 2018/7/1.
 */
public class JsonTools {
    public static Map<String, Object> parseMap(Object object) {
        Field[] fields = object.getClass().getDeclaredFields();
        EsTypeAnno anno;
        Object value = null;
        Map<String, Object> map = new HashMap<>();
        for (Field fi : fields) {
            anno = fi.getAnnotation(EsTypeAnno.class);
            if (anno != null) {
                fi.setAccessible(true);
                try {
                    value = fi.get(object);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                if (value != null) {
                    map.put(anno.propertyName(), value);
                }
            }
        }
        return map;
    }
}
